package com.sykj.why.controller.front.content;

import com.sykj.why.exception.WhyException;
import com.sykj.why.handler.Response;
import com.sykj.why.mongo.enums.exception.ResultEnum;
import com.sykj.why.mongo.service.ContentCategoryTService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Eleven
 * @date 2019/6/25
 * @desc 内容类型前端访问控制层
 */

@RestController
@RequestMapping(value = "/front/content/category")
@Slf4j
@Api(value = "/front/content/category",description = "内容类型前端访问控制层")
public class FrontContentCategoryController {

    @Autowired
    private ContentCategoryTService contentCategoryTService;

    /**
     * 查询内容类型列表
     *
     * @return
     */
    @RequestMapping(value = "/getCategoryList",method = RequestMethod.GET)
    @ApiOperation(value = "/getCategoryList",notes = "查询内容类型列表")
    public ResponseEntity getCategoryList(){
        try {
            return Response.success("查询成功", contentCategoryTService.findAll());
        } catch (WhyException e) {
            return Response.serverError(e.getMessage(), e.getCode());
        } catch (Exception e) {
            log.error("查询内容类型列表出现异常，{}", e.getMessage());
            return Response.serverError(ResultEnum.UNERROR.getMessage(), ResultEnum.UNERROR.getCode());
        }
    }

}
